package com.ruoyi.controller.achievements;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.achievements.AcvJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/acvJobManage")
public class AcvJobManageController extends BaseController {

    @Autowired
    AcvJobService acvJobService;

    private String prefix = "achievements/jobmanage";

    @GetMapping()
    public String AcvJobManageController() {
        return prefix + "/jobList";
    }

    @RequestMapping("/selectCurrencyJobList")
    @ResponseBody
    public TableDataInfo selectCurrencyJobList(@RequestParam Map map) {
        List<Map> mapList = acvJobService.selectCurrencyJobList(map);
        return getDataTable(mapList);
    }

    @RequestMapping("/selectCurrencyTemplateList")
    @ResponseBody
    public TableDataInfo selectCurrencyTemplateList(@RequestParam String jobId) {
        List<Map> mapList = acvJobService.selectCurrencyTemplateList(jobId);
        return getDataTable(mapList);
    }

    @RequestMapping("/updateTemplate")
    @ResponseBody
    public AjaxResult updateTemplate(MultipartFile file, String jobId) {
        return toAjax(acvJobService.updateTemplate(file, jobId));
    }

    @RequestMapping("/downloadTemplateByJobId")
    @ResponseBody
    public AjaxResult downloadTemplateByJobId(String jobId) {
        return acvJobService.downloadTemplateByJobId(jobId);
    }

    @GetMapping("/addJob")
    public String addJob() {
        return prefix + "/addJob";
    }

    @RequestMapping("/addJob")
    @ResponseBody
    public AjaxResult addJob(MultipartFile file, String jobName) {
        return toAjax(acvJobService.addJob(file,jobName));
    }

}
